package ee.tlnk.service;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * The Class PrototypeServlet.
 */
public class PrototypeServlet extends HttpServlet {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -4622422935527550424L;

	/**
	 * Write response.
	 *
	 * @param message the message
	 * @param request the request
	 * @param response the response
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	protected void writeResponse(ByteArrayOutputStream  message, HttpServletRequest request,
                      HttpServletResponse response) throws IOException {
	response.setContentType("text/xml");
	DataOutputStream ds = new DataOutputStream(response.getOutputStream());
	byte [] buffer = message.toByteArray();
	ds.write(buffer);
	ds.flush();
	ds.close();
	}
	
	/**
	 * Make input stream.
	 *
	 * @param message the message
	 * @param request the request
	 * @param response the response
	 * @return the string
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	protected String makeInputStream (ByteArrayOutputStream  message, HttpServletRequest request,
            HttpServletResponse response) throws IOException {
		ByteArrayOutputStream baos;
		DataOutputStream ds = new DataOutputStream(baos = new ByteArrayOutputStream());
		byte [] buffer = message.toByteArray();
		ds.write(buffer);
		ds.flush();
		ds.close();
		
	
		return baos.toString();
		
		
	}
}
